////////////////////////////////////////////////////////////////////////////////
// This file is part of the Mist compiler.                                    //
//                                                                            //
// Copyright (C) 2008, 2009 The Mist project                                  //
//                                                                            //
// For a list of contributors, see the COMMITTERS file.                       //
//                                                                            //
// The Mist compiler is free software: you can redistribute it and/or modify  //
// it under the terms of the GNU General Public License as published by       //
// the Free Software Foundation, either version 3 of the License, or          //
// (at your option) any later version.                                        //
//                                                                            //
// The Mist compiler is distributed in the hope that it will be useful,       //
// but WITHOUT ANY WARRANTY; without even the implied warranty of             //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              //
// GNU General Public License for more details.                               //
//                                                                            //
// You should have received a copy of the GNU General Public License          //
// in the COPYING file. If not, see <http://www.gnu.org/licenses/>.           //
////////////////////////////////////////////////////////////////////////////////

///
/// \file
/// Contains the abstract OutputProducer class and related global functions.
///

#ifndef OUTPUTPRODUCER_HPP
#define OUTPUTPRODUCER_HPP

////////////////////////////////////////////////////////////////////////////////
// Includes                                                                   //
////////////////////////////////////////////////////////////////////////////////

#include <string>
using std::string;

#include <ostream>
using std::ostream;

////////////////////////////////////////////////////////////////////////////////
// OutputProducer Class                                                       //
////////////////////////////////////////////////////////////////////////////////

/// An abstract class to be inherited by classes that can produce output by
/// sending it to an std::ostream. It expects the function send_to_stream to
/// be implemented, then provides an implicit cast to std::string and the
/// output-stream operator.
///
class OutputProducer {
	public:
		
		virtual ~OutputProducer() {}
		
		/// Implicit cast to string of any output-producing class.
		///
		operator string() const;
		
		/// Abstract function that is to be implemented by the concrete
		/// output-producing class. Sends output to the \a out stream.
		///
		virtual ostream& send_to_stream(ostream& out) const =0;
};

/// Send the output of \a producer to the \a out stream using operator<<.
///
/// \returns the \a out stream
/// \relates OutputProducer
///
ostream& operator<<(ostream& out, const OutputProducer& producer);

#endif // OUTPUTPRODUCER_HPP
